package com.android.webrtcsdkdev.net

import com.android.webrtcsdkdev.net.RetrofitClient.retrofit
import com.vc.videosdk.VcOperateManager
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit

/**

 * @Author : wy

 * @Time : On 2024/10/8 15:50

 * @Description : ApiClient

 */

object ApiClient {

    private var apiService: ApiService? = null



    fun getApiService() :ApiService{
        if(apiService==null){
            val BASE_URL = "http://vclusters.imwork.net:43286/api/blade-paas/"
            // const val IMG_URL = "$BASE_URL/image/"

             val okHttpClient = OkHttpClient.Builder()
                .callTimeout(30, TimeUnit.SECONDS)
                .connectTimeout(30, TimeUnit.SECONDS)
                .readTimeout(30, TimeUnit.SECONDS)
                .writeTimeout(30, TimeUnit.SECONDS)
                .retryOnConnectionFailure(true)// 重连
                .followRedirects(false)// 重定向
                .addInterceptor(RequestInterceptor())
                //.addInterceptor(ResponseInterceptor())
                .addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
                .build()

            val retrofit: Retrofit = Retrofit.Builder()
                .baseUrl(BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .client(okHttpClient)
                .build()
            apiService=retrofit.create(ApiService::class.java)
        }

        return apiService!!


       // apiService ?: retrofit.create(ApiService::class.java).also { apiService = it }
    }

}